// 管理系统相关类型定义

// 通用响应类型
export interface ApiResponse<T = any> {
  data?: T
  message?: string
  error?: string
  details?: any[]
}

// 分页响应类型
export interface PaginationResponse<T = any> {
  data: T[]
  pagination: {
    page: number
    limit: number
    total: number
    pages: number
  }
}

// 分类相关类型
export interface Category {
  id: number
  name: string
  slug: string
  description?: string
  icon?: string
  color?: string
  sortOrder: number
  isActive: boolean
  parentId?: number | null
  parent?: Category | null
  children?: Category[]
  lessons?: Lesson[]
  createdAt?: string
  updatedAt?: string
}

// 扩展的分类类型（用于前端显示）
export interface CategoryWithIndent extends Category {
  indentName: string
  level: number
}

// 课程相关类型
export interface Lesson {
  id: number
  categoryId: number
  title: string
  slug: string
  content: string
  excerpt?: string
  coverImage?: string
  difficulty: 'beginner' | 'intermediate' | 'advanced'
  duration?: number
  sortOrder: number
  isPublished: boolean
  isFeatured: boolean
  viewCount: number
  likeCount: number
  author?: string
  metaKeywords?: string
  metaDescription?: string
  createdAt: string
  updatedAt: string
  category?: Category
  tags?: Tag[]
  codeExamples?: CodeExample[]
}

// 课程表单数据类型（用于创建和更新）
export interface LessonFormData {
  title: string
  slug: string
  categoryId: number
  difficulty: 'beginner' | 'intermediate' | 'advanced'
  content: string
  excerpt?: string
  coverImage?: string
  duration?: number
  sortOrder?: number
  isPublished: boolean
  isFeatured: boolean
  author?: string
  metaKeywords?: string
  metaDescription?: string
  tags?: string[] | string // 支持数组或字符串格式
}

// 标签相关类型
export interface Tag {
  id: number
  name: string
  slug: string
  description?: string
  color?: string
  isActive: boolean
  lessonCount?: number
  createdAt: string
  updatedAt: string
}

// 代码示例相关类型
export interface CodeExample {
  id: number
  title: string
  lessonId: number
  language: string
  code: string
  description?: string
  fileName?: string
  sortOrder: number
  isRunnable: boolean
  createdAt: string
  updatedAt: string
  lesson?: {
    id: number
    title: string
    slug: string
  }
}

// 文件上传相关类型
export interface UploadFile {
  filename: string
  originalName: string
  mimetype: string
  size: number
  url: string
  path: string
  created?: string
  modified?: string
}

// 用户相关类型
export interface AdminUser {
  id: number
  username: string
  email: string
  role: 'admin' | 'editor'
  avatar?: string
  lastLoginAt?: string
  createdAt: string
}

// 登录相关类型
export interface LoginForm {
  username: string
  password: string
  remember?: boolean
}

export interface LoginResponse {
  token: string
  user: AdminUser
  expiresIn: number
}

// 表格查询参数
export interface QueryParams {
  page?: number
  limit?: number
  search?: string
  [key: string]: any
}

// 表单验证规则
export interface FormRule {
  required?: boolean
  message?: string
  type?: string
  min?: number
  max?: number
  pattern?: RegExp
  validator?: (rule: any, value: any, callback: any) => void
}

export interface FormRules {
  [key: string]: FormRule[]
} 